<?php
class site_k_index extends ss_konstrukt_masterComponent{
	protected $templates;
	protected $data;
	protected $structureMapper;
	protected $entryMapper;
	protected $strucure;
	protected $entries;
	
	public function __construct(
			ss_core_settings $ss_settings, 
			site_templatefactory $templates, 
			site_dao_structure_mapper $structureMapper, 
			site_dao_entry_mapper $entryMapper,
			ss_core_injectorInterface $injector){
		$this->structureMapper=$structureMapper;
		$this->entryMapper=$entryMapper;
		$this->structure=$structureMapper->master();
    	$this->templates = $templates;
		$this->settings=$ss_settings;
		parent::__construct($injector);
	}
	
	public function dispatch(){
		$this->node=$this->structure->getNodeFromSlug('/');
		$this->document->setTitle("Structure ".$this->node->headline());
		$this->entries=$this->entryMapper->master();
		return parent::dispatch();
	}
	
	public function GET(){
		ss_error::log('Index list GET');
		$this->content=array();
		foreach($this->entries as $obj){
			$this->content[]=$obj->master();
		}
		return parent::GET();
	}
	
	/*
	public function PUT(){
		ss_error::log($this->body());
	}
	*/
	protected function renderHtml() {
		
		ss_error::log($this->settings->server->appath->category,'Category');
    	$smarty = $this->templates->create();
	    $smarty->assign('content', $this->content);
	    //$smarty->assign('settings', $this->settings);
		$smarty->register_object('ss_path', $this->settings->server->appath);
	    $smarty->assign('context', $this);
    	return new k_HtmlResponse($smarty->fetch("master.tpl"));
    	//return $smarty->fetch("master.tpl");
	}
	/*
	protected function renderJson(){
		$json=array();
		foreach($this->structure as $obj){
			$json[]=$obj->getDetailData();
		}
		$response=new k_HttpResponse(200, json_encode($json) ,true);
		$response->setContentType('application/json');
		throw $response;
	}
	*/
}
?>